﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Example14.aspx.cs" Inherits="Chapter36.Example14" %>

<!DOCTYPE html>

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>代码清单 36-14 使用合成</title>
    <meta name="author" content="Adam Freeman" />
    <meta name="description" content="A simple example" />
    <link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
    <style>
        canvas {
            border: thin solid black;
            margin: 4px;
        }

        body > * {
            float: left;
        }
    </style>
</head>
<body>
    <canvas id="canvas" width="300" height="120">Your browser doesn't support the <code>canvas</code> element.</canvas>
    <label>Composition: </label>
    <select id="list">
        <option>copy</option>
        <option>destination-atop</option>
        <option>destination-in</option>
        <option>destination-over</option>
        <option>destination-out</option>
        <option>lighter</option>
        <option>source-atop</option>
        <option>source-in</option>
        <option>source-over</option>
        <option>source-out</option>
        <option>xor</option>
    </select>
    <script>
        var ctx = document.getElementById('canvas').getContext('2d');

        ctx.fillStyle = 'lightgrey';
        ctx.strokeStyle = 'black';
        ctx.lineWidth = 3;

        var value = 'copy';

        document.getElementById('list').onchange = function (e) {
            value = e.target.value;
            draw();
        }

        draw();

        function draw() {
            ctx.clearRect(0, 0, 300, 120);
            ctx.globalAlpha = 1.0;
            ctx.font = '60pt sans-serif';
            ctx.fillText('Hello', 10, 100);
            ctx.strokeText('Hello', 10, 100);

            ctx.globalCompositeOperation = value;

            ctx.fillStyle = 'red';
            ctx.globalAlpha = .5;
            ctx.fillRect(100, 10, 150, 100);
        }
    </script>
</body>
</html>
